OpenPrinterDialog Function

Displays the standard Print dialog box and returns a Graphics object in order to print to the currently selected printer.

Syntax

result = OpenPrinterDialog( [PageSetup], [window] )


Parameters

PageSetup (Optional)

PrinterSetup

Optional. A PrinterSetup object whose properties will be used (like page orientation, scale, etc.) when printing.

window (Optional)

Window

Optional. If you want to present the Print dialog as a Sheet window (Mac OS X only), window is the window to which you want to attach the Print dialog box.



Notes

The OpenPrinterDialog function returns a Graphics object. The various drawing routines can then be used to draw into the Graphics object and will be sent to the printer for printing. You can get the values in the Copies, From and To fields of the Print dialog box using the Copies, FirstPage and LastPage properties of the Graphics object returned by the OpenPrinterDialog function.

If the user clicks the Cancel button, the OpenPrinterDialog function returns Nil.

Since both parameters are optional, there is the possibility that you will want to pass the second parameter but not the first. If you pass only one parameter, REALbasic will assume that it is the first parameter. If you want to pass only the second parameter, pass Nil as the value of the first parameter, for example:

Dim g As Graphics
g = OpenPrinterDialog(Nil, myWindow)

Examples

This example prints "Hello World" to the currently selected printer.

Dim g As Graphics
g  = OpenPrinterDialog ()
If g<> Nil then
  g.DrawString "Hello World", 100, 100
End if

This example uses the Page Setup properties stored in the variable "ps" during printing:

Dim g As Graphics
g  = OpenPrinterDialog (ps)
g.DrawString "Hello World", 100, 100

See Also

Graphics, PrinterSetup, StyledTextPrinter classes; OpenPrinter function.